package com.zhengsr.wanandroid.ui.load;

import android.content.Context;

import com.wang.avi.AVLoadingIndicatorView;
import com.zhengsr.wanandroid.ui.cus.CusDialog;

/**
 * Created by zhengshaorui
 * time: 2018/8/19
 */

public class LoadingManager {
    private static final String TAG = "LoadingManager";
    private static final int LOADER_SIZE_SCALE = 8;
    private static CusDialog mDialog;

    private static void addLoadingView(Context context,LoadingType type){
        if (mDialog == null) {
            int width = context.getResources().getDisplayMetrics().widthPixels;
            int height = context.getResources().getDisplayMetrics().heightPixels;




                AVLoadingIndicatorView view = new AVLoadingIndicatorView(context);
                view.setIndicator(type.name());
                view.show();



            mDialog = new CusDialog.Builder()
                    .setContext(context)
                    .setLayoutView(view)
                    .setWidth(width / LOADER_SIZE_SCALE)
                    .setHeight(height / LOADER_SIZE_SCALE)
                    .builder();

        }else{
            mDialog.show();
        }
    }

    public static void show(Context context,LoadingType type){
        addLoadingView(context,type);
    }

    public static void hide(){
        if (mDialog != null){
            mDialog.dismiss();
        }
    }
}
